package cn.maihe.elg.operation.model.dto;

import cn.maihe.elg.operation.model.enums.InnerRespCode;
import org.apache.commons.lang3.ArrayUtils;

/**
 * @Description
 * @Author WJH
 * @Date 2021/04/25
 */
public class InnerBaseResp<T> extends BaseResp {

    private InnerRespCode respCode;
    private String message;
    private T data;
    /**
     * 原始响应码：即未转换前响应码
     */
    private String origCode;

    private Object reqObj;

    private InnerBaseResp(InnerRespCode respCode, String message, T data) {
        this.respCode = respCode;
        this.message = message;
        this.data = data;
    }

    public static <T> InnerBaseResp of(InnerRespCode respCode, String message, T data) {
        return new InnerBaseResp<T>(respCode, message, data);
    }

    public static <T> InnerBaseResp success(T data, String... msg) {
        return new InnerBaseResp<T>(InnerRespCode.SUCCESS, ArrayUtils.isNotEmpty(msg) ? msg[0] :"成功", data);
    }

    public static <T> InnerBaseResp error(T data, String... msg) {
        return new InnerBaseResp<T>(InnerRespCode.FAILURE, ArrayUtils.isNotEmpty(msg) ? msg[0] : "失败", data);
    }

    public static <T> InnerBaseResp exception(String message) {
        return new InnerBaseResp<T>(InnerRespCode.EXCEPTION, message, null);
    }

    public static <T> InnerBaseResp timeout(String message) {
        return new InnerBaseResp<T>(InnerRespCode.TIMEOUT, message, null);
    }

    public InnerRespCode getRespCode() {
        return respCode;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public Object getReqObj() {
        return reqObj;
    }

    public void setReqObj(Object reqObj) {
        this.reqObj = reqObj;
    }

    public String getOrigCode() {
        return origCode;
    }

    public InnerBaseResp setOrigCode(String origCode) {
        this.origCode = origCode;
        return this;
    }
}
